package cn.com.css.taxInspection.workflow.controller;

import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;

import cn.com.css.taxInspection.attention.entity.AjcxCondition;
import cn.com.css.taxInspection.gt3.entity.*;
import cn.com.css.taxInspection.gt3.service.*;
import cn.com.css.taxInspection.workflow.entity.WorkflowLogEntity;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import org.springframework.stereotype.Controller;

import cn.com.css.taxInspection.common.aop.annotation.LogAnnotation;
import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.system.entity.SysRole;
import cn.com.css.taxInspection.system.entity.SysUser;
import cn.com.css.taxInspection.system.entity.SysUserRole;
import cn.com.css.taxInspection.system.mapper.SysUserRoleMapper;
import cn.com.css.taxInspection.system.service.UserService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.constants.WorkflowConstants;
import cn.com.css.taxInspection.workflow.entity.WorkflowActivityEntity;
import cn.com.css.taxInspection.workflow.entity.WorkflowInspectionHearEntity;
import cn.com.css.taxInspection.workflow.entity.WorkflowMeetEntity;
import cn.com.css.taxInspection.workflow.service.WorkflowActivityService;
import cn.com.css.taxInspection.workflow.service.WorkflowInspectionHearService;
import cn.com.css.taxInspection.workflow.service.WorkflowMeetService;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

@Slf4j
@Controller
@RequestMapping("/workflow/activity")
public class WorkflowActivityController {

    @Resource
    private SysUserRoleMapper sysUserRoleMapper;
    @Resource
    private WorkflowInspectionHearService workflowInspectionHearService;
    @Resource
    private WorkflowActivityService workflowActivityService;
    @Resource
    private WorkflowMeetService workflowMeetService;
    @Resource
    private JcAjxxService jcAjxxService;
    @Resource
    private DmQxSwrysfService dmQxSwrysfService;
    @Resource
    private DmGySwjgService dmGySwjgService;
    @Resource
    private UserService userService;
    @Resource
    private HttpSessionService httpSessionService;
    @Resource
    private DmGySwryService dmGySwryService;
    @Resource
    private JcAjtzztbService jcAjtzztbService;
    @Resource
    private DmJcAjztService dmJcAjztService;
    @Resource
    private DmJcSwjcayztService dmJcSwjcayztService;
    @Resource
    private JcAyxxService jcAyxxService;
    @Resource
    private JcAjtzZcajxxService jcAjtzZcajxxService;
    @Resource
    private JcAjtzSlytzService jcAjtzSlytzService;

    @ApiOperation(value = "检查审理活动-锁定")
    @LogAnnotation(title = "检查审理活动", action = "锁定")
    @PostMapping("/lock")
    @ResponseBody
    @DS("oracle")
    public DataResult lock(@RequestBody WorkflowInspectionHearEntity workflowInspectionHear) {
        // 事务回滚
        workflowActivityService.lock(workflowInspectionHear);
        return DataResult.success();
    }

    @ApiOperation(value = "检查审理活动-活动记录")
    @LogAnnotation(title = "检查审理活动", action = "活动记录")
    @PostMapping("/record")
    // @RequiresPermissions("workflow:activity:record")
    @ResponseBody
    @DS("oracle")
    public DataResult record(@RequestBody WorkflowActivityEntity workflowActivityEntity) {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        String currentUserId = httpSessionService.getCurrentUserId();
        String relevance = workflowActivityEntity.getRelevance();
        LambdaQueryWrapper<WorkflowActivityEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(WorkflowActivityEntity::getRelevance, relevance);
        queryWrapper.orderByDesc(WorkflowActivityEntity::getCreateTime);
        List<WorkflowActivityEntity> list = workflowActivityService.list(queryWrapper);
        WorkflowInspectionHearEntity entity = workflowInspectionHearService.getById(relevance);
        if (TsBqUtils.isNotNull(entity)) {
            for (WorkflowActivityEntity activity : list) {
                activity.setRemark("系统流程");
            }
        } else {
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            /*
             * String djxh = jcAjxxEntity.getDjxh(); String ajjczt_dm =
             * jcAjxxEntity.getAjjczt_dm(); String slbm_dm =
             * jcAjxxEntity.getSlbm_dm(); String slry = jcAjxxEntity.getSlry();
             */

            // if(ajjczt_dm.contains("3")&&slbm_dm.equals(currentDeptId)&&slry.equals(currentUserId)){
            // 新建一条 workflowInspectionHear
            WorkflowInspectionHearEntity workflowInspectionHearEntity = new WorkflowInspectionHearEntity();
            workflowInspectionHearEntity.setId(relevance);
            workflowInspectionHearEntity.setRelevance(relevance);
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_20);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_20_NAME);
            workflowInspectionHearEntity.setInspectionMan11(jcAjxxEntity.getJcry());
            workflowInspectionHearEntity.setInspectionPost11(WorkflowConstants.ROLE_1708113478976823298);
            workflowInspectionHearEntity.setInspectionTaxorg11(jcAjxxEntity.getJcbmDm());
            workflowInspectionHearEntity.setHearMan21(currentUserId);
            workflowInspectionHearEntity.setHearPost21(WorkflowConstants.ROLE_1708113854186676225);
            workflowInspectionHearEntity.setHearTaxorg21(currentDeptId);
            workflowInspectionHearEntity.setDeleted(Constants.DELETEED_NOT);
            workflowInspectionHearEntity.setCreateTime(new Date());
            workflowInspectionHearEntity.setCreateId(currentUserId);
            workflowInspectionHearService.save(workflowInspectionHearEntity);
        }
        // 查询金三流程
        List<WorkflowActivityEntity> gt3List = workflowActivityService.getGt3Workflow(relevance);
        if (TsBqUtils.isNotNull(gt3List)) {
            for (WorkflowActivityEntity activity : gt3List) {
                list.add(activity);
            }
        }

        list.sort((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime()));
        for (WorkflowActivityEntity activity : gt3List) {
            String createId = activity.getCreateId();
            if (TsBqUtils.isNull(createId)) {
                activity.setCreateId("暂无");
            } else {
                SysUser sysUser = userService.getUser(createId);
                activity.setCreateId(sysUser.getNickName());
            }
        }
        return DataResult.success(list);
    }

    @ApiOperation(value = "检查审理活动-查看退回原因")
    @LogAnnotation(title = "检查审理活动", action = "查看退回原因")
    @PostMapping("/viewBack")
    @ResponseBody
    public DataResult viewBack(@RequestBody WorkflowActivityEntity workflowActivityEntity) {
        String jcajxxuuid = workflowActivityEntity.getJcajxxuuid();
        LambdaQueryWrapper<WorkflowActivityEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(WorkflowActivityEntity::getRelevance, jcajxxuuid);
        queryWrapper.like(WorkflowActivityEntity::getStateName, "退回");
        queryWrapper.orderByDesc(WorkflowActivityEntity::getCreateTime);
        List<WorkflowActivityEntity> list = workflowActivityService.list(queryWrapper);
        return DataResult.success(list.get(0));
    }

    @ApiOperation(value = "检查审理活动-退回")
    @LogAnnotation(title = "检查审理活动", action = "退回")
    @PostMapping("/backHear")
    // @RequiresPermissions("workflow:activity:back")
    @ResponseBody
    @DS("oracle")
    public DataResult backHear(@RequestBody WorkflowInspectionHearEntity workflowInspectionHear) {
        String currentUserId = httpSessionService.getCurrentUserId();
        Date date = new Date();
        String jcajxxuuid = workflowInspectionHear.getJcajxxuuid();
        String backContent = workflowInspectionHear.getInspectionContent();
        String inspectionMan = workflowInspectionHear.getInspectionMan();
        String[] split = inspectionMan.split("-");
        String identity = split[1];
        DmQxSwrysfEntity dmQxSwrysfEntity = dmQxSwrysfService.getUserIdentityByIdentity(identity);
        String taxorg = dmQxSwrysfEntity.getSfswjgDm();
        WorkflowInspectionHearEntity workflowInspectionHearEntity = workflowInspectionHearService
                .getByJcajxxuuid(jcajxxuuid);
        String stateCode = workflowInspectionHearEntity.getStateCode();
        WorkflowActivityEntity workflowActivityEntity = new WorkflowActivityEntity();
        if (stateCode.equals(WorkflowConstants.INSPECT_12)) {
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.INSPECT_121);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.INSPECT_121_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_4);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_4_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2108) || stateCode.equals(WorkflowConstants.HEAR_2107)
                || stateCode.equals(WorkflowConstants.HEAR_2106) || stateCode.equals(WorkflowConstants.HEAR_21)
                || stateCode.equals(WorkflowConstants.HEAR_20) || stateCode.equals(WorkflowConstants.HEAR_221)
                || stateCode.equals(WorkflowConstants.HEAR_231) || stateCode.equals(WorkflowConstants.HEAR_241)) {
            // 退回到检查人
            // TODO 判断是否到了审理环节，如果是审理环节需要进行配置
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2101);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2101_NAME);
            workflowInspectionHearEntity.setHearMan22(split[0]);
            workflowInspectionHearEntity.setHearContent22(backContent);
            workflowInspectionHearEntity.setHearTaxorg22(taxorg);
            workflowInspectionHearEntity.setHearPost22(WorkflowConstants.ROLE_1708113949602897922);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_31);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_31_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2105)) {
            // 退回到检查人
            // TODO 判断是否到了审理环节，如果是审理环节需要进行配置
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_211);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_211_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_10);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_10_CODE);
        } else {
            // TODO
            return DataResult.fail("stateCode状态不正确：" + stateCode);
        }
        workflowInspectionHearEntity.setUpdateTime(date);
        workflowInspectionHearEntity.setUpdateId(currentUserId);
        workflowInspectionHearService.updateById(workflowInspectionHearEntity);
        workflowActivityEntity.setId(TsBqUtils.getUUID());
        workflowActivityEntity.setRelevance(jcajxxuuid);
        workflowActivityEntity.setCurrentMan(currentUserId);
        workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
        workflowActivityEntity.setCreateTime(date);
        workflowActivityEntity.setCreateId(currentUserId);
        workflowActivityService.saveByWorkflowActivity(workflowActivityEntity);
        return DataResult.success();
    }

    @ApiOperation(value = "检查审理活动-退回")
    @LogAnnotation(title = "检查审理活动", action = "退回")
    @PostMapping("/back")
    // @RequiresPermissions("workflow:activity:back")
    @ResponseBody
    @DS("oracle")
    public DataResult back(@RequestBody WorkflowActivityEntity workflowActivityEntity) {
        String currentUserId = httpSessionService.getCurrentUserId();
        Date date = new Date();
        String jcajxxuuid = workflowActivityEntity.getJcajxxuuid();
        String backContent = workflowActivityEntity.getBackContent();
        WorkflowInspectionHearEntity workflowInspectionHearEntity = workflowInspectionHearService
                .getByJcajxxuuid(jcajxxuuid);
        String stateCode = workflowInspectionHearEntity.getStateCode();
        if (stateCode.equals(WorkflowConstants.INSPECT_12)) {
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.INSPECT_121);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.INSPECT_121_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_4);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_4_CODE);
        } else if (stateCode.equals(WorkflowConstants.INSPECT_13)) {
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.INSPECT_131);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.INSPECT_131_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_7);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_7_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_21) || stateCode.equals(WorkflowConstants.HEAR_2105)) {
            // 退回到检查人
            // TODO 判断是否到了审理环节，如果是审理环节需要进行配置
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_211);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_211_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_10);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_10_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_22)) {
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_221);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_221_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_13);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_13_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_23)) {
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_231);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_231_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_16);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_16_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_24)) {
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_241);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_241_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_19);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_19_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2101)) {
            // 复审
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2106);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2106_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_35);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_35_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2103)) {
            // 科长
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2107);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2107_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_36);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_36_CODE);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2104)) {
            // 局长
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2108);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2108_NAME);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_37);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_37_CODE);
        } else {
            // TODO
            return DataResult.fail("stateCode状态不正确：" + stateCode);
        }
        workflowInspectionHearEntity.setUpdateTime(date);
        workflowInspectionHearEntity.setUpdateId(currentUserId);
        workflowInspectionHearService.updateById(workflowInspectionHearEntity);
        workflowActivityEntity.setId(TsBqUtils.getUUID());
        workflowActivityEntity.setRelevance(jcajxxuuid);
        workflowActivityEntity.setContent(backContent);
        workflowActivityEntity.setCurrentMan(currentUserId);
        workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
        workflowActivityEntity.setCreateTime(date);
        workflowActivityEntity.setCreateId(currentUserId);
        workflowActivityService.saveByWorkflowActivity(workflowActivityEntity);
        return DataResult.success();
    }

    @ApiOperation(value = "检查审理活动-推送")
    @LogAnnotation(title = "检查审理活动", action = "推送")
    @PostMapping("/push")
    // @RequiresPermissions("workflow:activity:push")
    @ResponseBody
    @DS("oracle")
    public DataResult push(@RequestBody WorkflowInspectionHearEntity workflowInspectionHear) {
        Date date = new Date();
        String currentUserId = httpSessionService.getCurrentUserId();
        String inspectionContent = workflowInspectionHear.getInspectionContent();
        String jcajxxuuid = workflowInspectionHear.getJcajxxuuid();
        if (TsBqUtils.isNull(jcajxxuuid)) {
            return DataResult.fail("jcajxxuuid不能为NULL!");
        }
        WorkflowInspectionHearEntity workflowInspectionHearEntity = workflowInspectionHearService.getById(jcajxxuuid);
        String stateCode = workflowInspectionHearEntity.getStateCode();
        String _inspectionMan = workflowInspectionHear.getInspectionMan();
        String taxorg = "";
        String inspectionMan = "";
        if (!(stateCode.equals(WorkflowConstants.HEAR_2104) || stateCode.equals(WorkflowConstants.HEAR_24)
                || stateCode.equals(WorkflowConstants.INSPECT_13))) {
            if (TsBqUtils.isNull(_inspectionMan)) {
                return DataResult.fail("inspectionMan不能为NULL!");
            }

            String[] split = _inspectionMan.split("-");
            String identity = split[1];
            DmQxSwrysfEntity dmQxSwrysfEntity = dmQxSwrysfService.getUserIdentityByIdentity(identity);
            taxorg = dmQxSwrysfEntity.getSfswjgDm();
            inspectionMan = split[0];
        }
        WorkflowActivityEntity workflowActivityEntity = new WorkflowActivityEntity();
        if (stateCode.equals(WorkflowConstants.INSPECT_11) || stateCode.equals(WorkflowConstants.INSPECT_121)
                || stateCode.equals(WorkflowConstants.INSPECT_131) || stateCode.equals(WorkflowConstants.HEAR_211)) {
            // 检查- 检查人 推送 检查科长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.INSPECT_12);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.INSPECT_12_NAME);
            workflowInspectionHearEntity.setInspectionMan12(inspectionMan);
            workflowInspectionHearEntity.setInspectionContent11(inspectionContent);
            workflowInspectionHearEntity.setInspectionTaxorg12(taxorg);
            workflowInspectionHearEntity.setInspectionPost12(WorkflowConstants.ROLE_1708113663597502466);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_1);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_1_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.INSPECT_12)) {
            // 检查-科科长 推送 检查局长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.INSPECT_13);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.INSPECT_13_NAME);
            workflowInspectionHearEntity.setInspectionMan13(inspectionMan);
            workflowInspectionHearEntity.setInspectionContent12(inspectionContent);
            workflowInspectionHearEntity.setInspectionTaxorg13(taxorg);
            workflowInspectionHearEntity.setInspectionPost13(WorkflowConstants.ROLE_1708113753208807426);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_3);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_3_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.INSPECT_13)) {
            // 检查-科主管局长 推送 检查员
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.INSPECT_14);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.INSPECT_14_NAME);
            // workflowInspectionHearEntity.setHearMan21(inspectionMan);
            // workflowInspectionHearEntity.setHearContent21(inspectionContent);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_6);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_6_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.INSPECT_14)) {
            // 检查- 检查员推送 审理员
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_21);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_21_NAME);
            workflowInspectionHearEntity.setHearMan21(inspectionMan);
            workflowInspectionHearEntity.setHearContent21(inspectionContent);
            String sjswjgDm = dmGySwjgService.getSjswjgDm(taxorg);
            workflowInspectionHearEntity.setHearTaxorg21(sjswjgDm);
            workflowInspectionHearEntity.setHearPost21(WorkflowConstants.ROLE_1708113854186676225);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_8_1);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_8_1_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_20) || stateCode.equals(WorkflowConstants.HEAR_21)
                || stateCode.equals(WorkflowConstants.HEAR_241) || stateCode.equals(WorkflowConstants.HEAR_221)
                || stateCode.equals(WorkflowConstants.HEAR_25) || stateCode.equals(WorkflowConstants.HEAR_231)
                // 退回逻辑后在进行推送逻辑
                || stateCode.equals(WorkflowConstants.HEAR_2106)
        ) {
            // 审理-审理员 推送副审
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_22);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_22_NAME);
            workflowInspectionHearEntity.setHearMan22(inspectionMan);
            workflowInspectionHearEntity.setHearContent22(inspectionContent);
            workflowInspectionHearEntity.setHearTaxorg22(taxorg);
            workflowInspectionHearEntity.setHearPost22(WorkflowConstants.ROLE_1708113949602897922);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_9);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_9_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_22)) {
            // 审理- 审理复审推送科长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_23);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_23_NAME);
            workflowInspectionHearEntity.setHearMan23(inspectionMan);
            workflowInspectionHearEntity.setHearContent23(inspectionContent);
            workflowInspectionHearEntity.setHearTaxorg23(taxorg);
            workflowInspectionHearEntity.setHearPost23(WorkflowConstants.ROLE_1708114028845883394);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_12);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_12_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_23)) {
            // 审理-审理科长 推送 局长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_24);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_24_NAME);
            workflowInspectionHearEntity.setHearMan24(inspectionMan);
            workflowInspectionHearEntity.setHearContent24(inspectionContent);
            workflowInspectionHearEntity.setHearTaxorg24(taxorg);
            workflowInspectionHearEntity.setHearPost24(WorkflowConstants.ROLE_1708114123976892418);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_18);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_18_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_24)) {
            // 审理-审理主管局长 推送审理员
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_25);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_25_NAME);
            workflowInspectionHearEntity.setHearMan25(currentUserId);
            workflowInspectionHearEntity.setHearContent25(inspectionContent);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_20);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_20_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_26)) {
            // 会议审 TODO

            // 申请退回流程
        } else if (stateCode.equals(WorkflowConstants.HEAR_2101)) {

            // 申请退回流程 复审-》科长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2103);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2103_NAME);
            workflowInspectionHearEntity.setHearMan23(inspectionMan);
            workflowInspectionHearEntity.setHearContent23(inspectionContent);
            workflowInspectionHearEntity.setHearTaxorg23(taxorg);
            workflowInspectionHearEntity.setHearPost23(WorkflowConstants.ROLE_1708114028845883394);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_32);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_32_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2103)) {
            // 申请退回流程 科长-》局长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2104);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2104_NAME);
            workflowInspectionHearEntity.setHearMan24(inspectionMan);
            workflowInspectionHearEntity.setHearContent24(inspectionContent);
            workflowInspectionHearEntity.setHearTaxorg24(taxorg);
            workflowInspectionHearEntity.setHearPost24(WorkflowConstants.ROLE_1708114123976892418);
            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);
            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_33);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_33_CODE);
            workflowActivityEntity.setContent(inspectionContent);
            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);
        } else if (stateCode.equals(WorkflowConstants.HEAR_2104)) {

            // 审理-审理科长 推送 局长
            // 处理 workflowInspectionHear 表
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_2105);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_2105_NAME);
            // workflowInspectionHearEntity.setHearMan24(inspectionMan);
            workflowInspectionHearEntity.setHearContent25(inspectionContent);

            workflowInspectionHearEntity.setHearTaxorg25(taxorg);
            workflowInspectionHearEntity.setHearPost25(WorkflowConstants.ROLE_1708114123976892418);

            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);

            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_34);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_34_CODE);

            workflowActivityEntity.setContent(inspectionContent);

            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);

        } else if (stateCode.equals(WorkflowConstants.HEAR_2105)) {
            // 申请退回流程 局长-》审理员
            // 处理 workflowInspectionHear 表
            // TODO
            workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_24);
            workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_24_NAME);
            workflowInspectionHearEntity.setHearMan24(inspectionMan);
            workflowInspectionHearEntity.setHearContent24(inspectionContent);

            workflowInspectionHearEntity.setHearTaxorg24(taxorg);
            workflowInspectionHearEntity.setHearPost24(WorkflowConstants.ROLE_1708114123976892418);

            workflowInspectionHearEntity.setUpdateTime(date);
            workflowInspectionHearEntity.setUpdateId(currentUserId);

            // 处理 workflowActivityEntity 表
            workflowActivityEntity.setId(TsBqUtils.getUUID());
            workflowActivityEntity.setRelevance(jcajxxuuid);
            workflowActivityEntity.setCurrentMan(currentUserId);
            workflowActivityEntity.setStateName(WorkflowConstants.ACTIVITY_18);
            workflowActivityEntity.setStateCode(WorkflowConstants.ACTIVITY_18_CODE);

            workflowActivityEntity.setContent(inspectionContent);

            workflowActivityEntity.setDeleted(Constants.DELETEED_NOT);
            workflowActivityEntity.setCreateTime(date);
            workflowActivityEntity.setCreateId(currentUserId);

        } else {
            return DataResult.fail("stateCode状态不正确：" + stateCode);

        }

        workflowInspectionHearService.updateByWorkflowInspectionHearEntity(workflowInspectionHearEntity);
        workflowActivityService.saveByWorkflowActivity(workflowActivityEntity);

        return DataResult.success();

    }

    @ApiOperation(value = "检查审理活动-出两书")
    @LogAnnotation(title = "检查审理活动", action = "出两书")
    @PostMapping("/twoBooks")
    @ResponseBody
    @DS("oracle")
    public DataResult twoBooks(@RequestBody WorkflowActivityEntity workflowActivityEntity) {

        Date date = new Date();
        String content = workflowActivityEntity.getTwoBooksContent();
        String currentUserId = httpSessionService.getCurrentUserId();
        String jcajxxuuid = workflowActivityEntity.getJcajxxuuid();

        WorkflowInspectionHearEntity workflowInspectionHearEntity = workflowInspectionHearService
                .getByJcajxxuuid(jcajxxuuid);
        String stateCode = workflowInspectionHearEntity.getStateCode();
        if (!stateCode.equals(WorkflowConstants.HEAR_25)) {
            return DataResult.fail("当前stateCode状态不正确：" + stateCode);
        }
        workflowInspectionHearEntity.setStateCode(WorkflowConstants.HEAR_27);
        workflowInspectionHearEntity.setStateName(WorkflowConstants.HEAR_27_NAME);
        workflowInspectionHearEntity.setUpdateTime(date);
        workflowInspectionHearEntity.setUpdateId(currentUserId);

        workflowInspectionHearService.updateByWorkflowInspectionHearEntity(workflowInspectionHearEntity);

        WorkflowActivityEntity workflowActivity = new WorkflowActivityEntity();
        workflowActivity.setId(TsBqUtils.getUUID());
        workflowActivity.setRelevance(jcajxxuuid);
        workflowActivity.setCurrentMan(currentUserId);
        workflowActivity.setStateName(WorkflowConstants.ACTIVITY_21);
        workflowActivity.setStateCode(WorkflowConstants.ACTIVITY_21_CODE);

        workflowActivity.setContent(content);

        workflowActivity.setDeleted(Constants.DELETEED_NOT);
        workflowActivity.setCreateTime(date);
        workflowActivity.setCreateId(currentUserId);

        workflowActivityService.saveByWorkflowActivity(workflowActivity);

        return DataResult.success();
    }

    @ApiOperation(value = "检查审理活动-会议审")
    @LogAnnotation(title = "检查审理活动", action = "会议审")
    @PostMapping("/meeting")
    @ResponseBody
    @DS("oracle")
    public DataResult meeting(@RequestBody WorkflowActivityEntity workflowActivityEntity) {
        Date date = new Date();
        String currentUserId = httpSessionService.getCurrentUserId();
        String jcajxxuuid = workflowActivityEntity.getJcajxxuuid();
        if (TsBqUtils.isNull(jcajxxuuid)) {
            return DataResult.fail("jcajxxuuid不能为NULL！");
        }

        String meetMans = workflowActivityEntity.getMeetMans();

        if (TsBqUtils.isNull(meetMans)) {
            return DataResult.fail("meetMans不能为NULL！");
        }
        List<String> meetManList = Arrays.asList(meetMans.split(","));

        for (String string : meetManList) {
            WorkflowMeetEntity workflowMeetEntity = new WorkflowMeetEntity();
            workflowMeetEntity.setId(TsBqUtils.getUUID());
            workflowMeetEntity.setRelevance(jcajxxuuid);
            String[] split = string.split("-");
            workflowMeetEntity.setMeetMan(split[0]);
            workflowMeetEntity.setMeetManDeno(",");
            workflowMeetEntity.setDeleted(Constants.DELETEED_NOT);
            workflowMeetEntity.setCreateTime(date);
            workflowMeetEntity.setCreateId(currentUserId);
            workflowMeetService.saveByWorkflowMeetEntity(workflowMeetEntity);

            WorkflowActivityEntity workflowActivity = new WorkflowActivityEntity();
            workflowActivity.setId(TsBqUtils.getUUID());
            workflowActivity.setRelevance(jcajxxuuid);
            workflowActivity.setCurrentMan(currentUserId);
            workflowActivity.setStateName(WorkflowConstants.ACTIVITY_22);
            workflowActivity.setStateCode(WorkflowConstants.ACTIVITY_22_CODE);
            workflowActivity.setContent(meetMans);

            workflowActivity.setDeleted(Constants.DELETEED_NOT);
            workflowActivity.setCreateTime(date);
            workflowActivity.setCreateId(currentUserId);

            workflowActivityService.saveByWorkflowActivity(workflowActivity);
        }


        return DataResult.success();
    }

    @ApiOperation(value = "检查审理活动-会议审回复")
    @LogAnnotation(title = "检查审理活动", action = "会议审回复")
    @PostMapping("/meetingReply")
    // @RequiresPermissions("workflow:activity:meetingReply")
    @ResponseBody
    @DS("oracle")
    public DataResult meetingReply(@RequestBody WorkflowActivityEntity workflowActivityEntity) {
        Date date = new Date();
        String currentUserId = httpSessionService.getCurrentUserId();
        String meetId = workflowActivityEntity.getMeetId();

        String meetContent = workflowActivityEntity.getMeetContent();

        if (TsBqUtils.isNull(meetId)) {
            return DataResult.fail("jcajxxuuid不能为NULL！");
        }

        WorkflowMeetEntity workflowMeetEntity = workflowMeetService.getById(meetId);
        String meetManDeno = workflowMeetEntity.getMeetManDeno();
        String _meetManDeno = "";
        if (meetManDeno.equals(",")) {
            _meetManDeno = currentUserId;
        } else {

            _meetManDeno = meetManDeno + "," + currentUserId;
        }

        workflowMeetEntity.setMeetManDeno(_meetManDeno);
        workflowMeetEntity.setUpdateTime(date);
        workflowMeetEntity.setUpdateId(currentUserId);

        workflowMeetService.updateById(workflowMeetEntity);

        WorkflowActivityEntity workflowActivity = new WorkflowActivityEntity();
        workflowActivity.setId(TsBqUtils.getUUID());
        workflowActivity.setRelevance(workflowMeetEntity.getRelevance());
        workflowActivity.setCurrentMan(currentUserId);
        workflowActivity.setStateName(WorkflowConstants.ACTIVITY_23);
        workflowActivity.setStateCode(WorkflowConstants.ACTIVITY_23_CODE);

        workflowActivity.setContent(meetContent);

        workflowActivity.setDeleted(Constants.DELETEED_NOT);
        workflowActivity.setCreateTime(date);
        workflowActivity.setCreateId(currentUserId);

        workflowActivityService.saveByWorkflowActivity(workflowActivity);

        return DataResult.success();
    }

    @ApiOperation(value = "检查审理活动-获取岗位人员")
    @LogAnnotation(title = "检查审理活动", action = "获取岗位人员")
    @PostMapping("/postman")
    @ResponseBody
    public DataResult postman(@RequestBody SysRole sysRole) {
        String id = sysRole.getId();
        String currentDeptId = httpSessionService.getCurrentDeptId();
        if (TsBqUtils.isNull(id)) {
            return DataResult.fail("入参岗位ID不能为null");
        }
        List<String> userIdList = new ArrayList<>();
        LambdaQueryWrapper<SysUserRole> sysUserRoleQueryWrapper = Wrappers.lambdaQuery();
        sysUserRoleQueryWrapper.eq(SysUserRole::getRoleId, id);
        List<SysUserRole> sysUserRoleList = sysUserRoleMapper.selectList(sysUserRoleQueryWrapper);
        for (SysUserRole sysUserRole : sysUserRoleList) {
            String userId = sysUserRole.getUserId();
            userIdList.add(userId);
        }

        if (TsBqUtils.isNull(userIdList)) {
            return DataResult.fail("岗位ID:" + id + "，没有配置人员！请联系管理员配置人员！");
        }

        LambdaQueryWrapper<DmQxSwrysfEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.likeRight(DmQxSwrysfEntity::getSfswjgDm, currentDeptId.substring(0, 9));
        queryWrapper.eq(DmQxSwrysfEntity::getYxbz, "Y");
        queryWrapper.in(DmQxSwrysfEntity::getSwrysfDm, userIdList);
        List<DmQxSwrysfEntity> list = dmQxSwrysfService.list(queryWrapper);

        // 过滤 检查人环节-办理 推送检查科科长时 本部分
        List<DmQxSwrysfEntity> listHandle = new ArrayList<>();

        if (id.equals(WorkflowConstants.ROLE_1708113663597502466)) {
            for (DmQxSwrysfEntity dmQxSwrysfEntity : list) {
                String sfswjgDm = dmQxSwrysfEntity.getSfswjgDm();
                if (currentDeptId.equals(sfswjgDm)) {
                    listHandle.add(dmQxSwrysfEntity);
                }
            }
        } else {
            listHandle = list;
        }

        return DataResult.success(listHandle);

    }

    @ApiOperation(value = "查询-获取本局机关列表")
    @LogAnnotation(title = "查询", action = "获取本局机关列表")
    @PostMapping("/debugtaxorg")
    @ResponseBody
    public DataResult debugtaxorg() {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        List<DmGySwjgEntity> list = dmGySwjgService.selectBycurrentDeptId(currentDeptId);
        return DataResult.success(list);
    }

    @ApiOperation(value = "查询-获取全市列表")
    @LogAnnotation(title = "查询", action = "获取全市列表")
    @PostMapping("/qsSwjgSelect")
    @ResponseBody
    public DataResult qsSwjgSelect() {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        List<DmGySwjgEntity> list = dmGySwjgService.selectQsSwjgById(currentDeptId);
        return DataResult.success(list);
    }

    @ApiOperation(value = "查询-获取全局列表")
    @LogAnnotation(title = "查询", action = "获取全局列表")
    @PostMapping("/qjSwjgSelect")
    @ResponseBody
    public DataResult qjSwjgSelect() {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        List<DmGySwjgEntity> list = dmGySwjgService.selectBycurrentDeptId(currentDeptId);
        return DataResult.success(list);
    }


    @ApiOperation(value = "获取案件调整状态下拉选")
    @LogAnnotation(title = "案件调整", action = "获取案件状态下拉选")
    @PostMapping("/getAjzt")
    @ResponseBody
    @DS("oracle")
    public DataResult getAjzt() {
        List<DmJcAjztEntity> list = dmJcAjztService.list();
        return DataResult.success(list);
    }

    @ApiOperation(value = "案件调整")
    @LogAnnotation(title = "自查检查人员调整", action = "自查案件状态下拉选")
    @PostMapping("/getzcAjzt")
    @ResponseBody
    @DS("oracle")
    public DataResult getzcAjzt() {
        List<DmJcSwjcayztEntity> list = dmJcSwjcayztService.list();
        return DataResult.success(list);
    }

    @ApiOperation(value = "导出案件信息")
    @LogAnnotation(title = "案件调整", action = "导出案件信息")
    @PostMapping("/exportData")
    @ResponseBody
    @DS("oracle")
    public DataResult exportData(@RequestBody JcAjtzztbEntity jcAjtzztbEntity) throws ParseException {
        List<JcAjtzztbEntity> jcAjtzztbEntityList = jcAjtzztbService.queryJcajtzztbEntityList(jcAjtzztbEntity);
        return DataResult.success(jcAjtzztbEntityList);
    }

    @ApiOperation(value = "案件调整-获取调整检查人列表")
    @LogAnnotation(title = "立案检查人员调整", action = "获取金三检查人")
    @PostMapping("/querySelectJcr")
    @ResponseBody
    public DataResult querySelectJcr(@RequestBody String currentDeptId) {
        String swjgdm = TsBqUtils.isNull(currentDeptId) ? httpSessionService.getCurrentDeptId() : currentDeptId;
        List<DmGySwryEntity> dmGySwjgEntityList = dmGySwryService.queryLajcrytzList(swjgdm.substring(0, 9));
        for (DmGySwryEntity dmGySwryEntity : dmGySwjgEntityList) {
            dmGySwryEntity.setSwryxm(dmGySwryEntity.getSwryDm() + "|" + dmGySwryEntity.getSwryxm());
        }
        return DataResult.success(dmGySwjgEntityList);
    }

    @ApiOperation(value = "案件调整-立案检查人员调整")
    @LogAnnotation(title = "立案检查人员调整", action = "保存主调查人")
    @PostMapping("/saveZjcr")
    @ResponseBody
    @DS("oracle")
    public DataResult saveZjcr(@RequestBody JcAjtzztbEntity jcAjtzztbEntity) {
        //设置主调查人
        jcAjtzztbEntity.setSjzc(TsBqUtils.isNotNull(jcAjtzztbEntity.getSelectedValue()) && !jcAjtzztbEntity.getSelectedValue().isEmpty()
                ? jcAjtzztbEntity.getSelectedValue().replaceAll("[\\[\\]\"]", "")
                : jcAjtzztbEntity.getJszc());
        //设置协助调查人
        jcAjtzztbEntity.setSjxc(TsBqUtils.isNotNull(jcAjtzztbEntity.getXcSelectedValue()) && !jcAjtzztbEntity.getXcSelectedValue().isEmpty()
                ? jcAjtzztbEntity.getXcSelectedValue().replaceAll("[\\[\\]\"]", "")
                : jcAjtzztbEntity.getSjxc());
        jcAjtzztbEntity.setJcrlx(Constants.AJZT_LX_YTZ);
        Boolean results = jcAjtzztbService.updateById(jcAjtzztbEntity);
        return DataResult.success(results);
    }


    @ApiOperation(value = "案件调整")
    @LogAnnotation(title = "自查检查人员调整", action = "保存自查调查人")
    @PostMapping("/saveZcjcr")
    @ResponseBody
    @DS("oracle")
    public DataResult saveZcjcr(@RequestBody JcAjtzZcajxxEntity jcAjtzZcajxxEntity) {
        //设置主调查人
        String Zc = TsBqUtils.isNotNull(jcAjtzZcajxxEntity.getSelectedValue()) && !jcAjtzZcajxxEntity.getSelectedValue().isEmpty()
                ? jcAjtzZcajxxEntity.getSelectedValue().replaceAll("[\\[\\]\"]", "")
                : jcAjtzZcajxxEntity.getSwryxm();
        String xc = TsBqUtils.isNotNull(jcAjtzZcajxxEntity.getXcSelectedValue()) && !jcAjtzZcajxxEntity.getXcSelectedValue().isEmpty()
                ? jcAjtzZcajxxEntity.getXcSelectedValue().replaceAll("[\\[\\]\"]", "")
                : jcAjtzZcajxxEntity.getSwryxm();
        //设置协助调查人
        jcAjtzZcajxxEntity.setSwryxm("主查:" + Zc + ", 协查：" + xc);
        jcAjtzZcajxxEntity.setZcrylx(Constants.AJZT_LX_YTZ);
        Boolean results = jcAjtzZcajxxService.updateById(jcAjtzZcajxxEntity);
        return DataResult.success(results);
    }

    @ApiOperation(value = "案件调整")
    @LogAnnotation(title = "审理员调整", action = "保存审理员")
    @PostMapping("/saveSly")
    @ResponseBody
    @DS("oracle")
    public DataResult saveSly(@RequestBody JcAjztSlytzEntity jcAjztSlytzEntity) {
        //设置主调查人
        String slr = TsBqUtils.isNotNull(jcAjztSlytzEntity.getXcSelectedValue()) && !jcAjztSlytzEntity.getXcSelectedValue().isEmpty()
                ? jcAjztSlytzEntity.getXcSelectedValue().replaceAll("[\\[\\]\"]", "")
                : jcAjztSlytzEntity.getSlry();
        //设置协助调查人
        jcAjztSlytzEntity.setSjslr(slr);
        jcAjztSlytzEntity.setSllx(Constants.AJZT_LX_YTZ);
        Boolean results = jcAjtzSlytzService.updateById(jcAjztSlytzEntity);
        return DataResult.success(results);
    }

    @ApiOperation(value = "检查审理活动-受理人")
    @LogAnnotation(title = "检查审理活动", action = "受理人")
    @PostMapping("/list")
    @ResponseBody
    @DS("oracle")
    public DataResult list(@RequestBody WorkflowInspectionHearEntity workflowInspectionHear) {
        String currentUserId = httpSessionService.getCurrentUserId();
        // Page page = new Page(workflowInspectionHear.getPage(), workflowInspectionHear.getLimit());
        LambdaQueryWrapper<WorkflowInspectionHearEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(WorkflowInspectionHearEntity::getInspectionMan11, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getInspectionMan12, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getInspectionMan13, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getHearMan21, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getHearMan22, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getHearMan23, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getHearMan24, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getHearMan25, currentUserId).or()
                .eq(WorkflowInspectionHearEntity::getHearMan26, currentUserId);
        List<WorkflowInspectionHearEntity> list = workflowInspectionHearService.list(queryWrapper);
        List<String> listJcajxxuuid = new ArrayList<>();
        for (WorkflowInspectionHearEntity inspectionHear : list) {
            String relevance = inspectionHear.getRelevance();
            listJcajxxuuid.add(relevance);
        }
        JcAjxxEntity jcAjxxEntity = new JcAjxxEntity();
        jcAjxxEntity.setJcry(currentUserId);
        List<JcAjxxEntity> jcAjxxEntityList = jcAjxxService.getByJcAjxx(jcAjxxEntity);
        for (JcAjxxEntity jcAjxx : jcAjxxEntityList) {
            String jcajxxuuid = jcAjxx.getJcajxxuuid();
            listJcajxxuuid.add(jcajxxuuid);
        }
        List<JcAjxxEntity> listJcAjxxEntity = new ArrayList<>();
        // list 去重
        List<String> records = listJcajxxuuid.stream().distinct().collect(Collectors.toList());
        for (String jcajxxuuid : records) {
            JcAjxxEntity jcAjxx = jcAjxxService.getByJcajxxuuid(jcajxxuuid);
            listJcAjxxEntity.add(jcAjxx);
        }
        return DataResult.success(listJcAjxxEntity);
    }

    @ApiOperation(value = "检查审理活动-受理人")
    @LogAnnotation(title = "检查审理活动", action = "受理人")
    @PostMapping("/list1")
    @ResponseBody
    @DS("oracle")
    public DataResult list1(@RequestBody WorkflowInspectionHearEntity workflowInspectionHear) {
        String currentUserId = httpSessionService.getCurrentUserId();
        IPage<JcAjxxEntity> iPage = jcAjxxService.pageInfoByJcrAndSlrAndZxr(workflowInspectionHear, currentUserId);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "工作调度-查询案件信息")
    @LogAnnotation(title = "工作调度", action = "查询案件信息")
    @PostMapping("/queryGzddAjxx")
    @ResponseBody
    @DS("oracle")
    public DataResult queryGzddAjxx(@RequestBody JcAjxxEntity jcAjxxEntity) {
        IPage<JcAjxxEntity> iPage = jcAjxxService.queryAjxxList(jcAjxxEntity);
        return DataResult.success(iPage);
    }


    /*
     * @ApiOperation(value = "检查审理活动-上传")
     *
     * @LogAnnotation(title = "检查审理活动", action = "上传")
     *
     * @PostMapping("/upload")
     *
     * @RequiresPermissions("workflow:activity:upload")
     *
     * @ResponseBody public DataResult upload(@RequestParam(value = "file")
     * MultipartFile file, HttpServletRequest httpServletRequest) {
     *
     * String jcajxxuuid = httpServletRequest.getParameter("jcajxxuuid"); if
     * (TsBqUtils.isEmpty(jcajxxuuid)) { return
     * DataResult.fail("入参sjbh不能为null！"); }
     *
     * String currentUserId = httpSessionService.getCurrentUserId(); if
     * (TsBqUtils.isEmpty(currentUserId)) { return
     * DataResult.fail("入参currentUserId不能为null！"); }
     *
     * // 判断文件是否空 if (file == null || file.getOriginalFilename() == null ||
     * "".equalsIgnoreCase(file.getOriginalFilename().trim())) { return
     * DataResult.fail("上传文件为空"); } Map<String, Object> columnMap = new
     * HashMap<>(); columnMap.put("sjbh", jcajxxuuid);
     * columnMap.put("create_id", currentUserId);
     *
     * List<FwdSjfjlbEntity> listByMap = fwdSjfjlbService.listByMap(columnMap);
     *
     * if(listByMap.size() > 1){ return
     * DataResult.fail("每个环节节点只允许上传2个文件！当前人员上传数量超过2个！"); } // 存储文件夹 String
     * createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN); String
     * newPath = fileUploadProperties.getPath() + createTime + File.separator;
     * File uploadDirectory = new File(newPath); if (uploadDirectory.exists()) {
     * if (!uploadDirectory.isDirectory()) { uploadDirectory.delete(); } } else
     * { uploadDirectory.mkdir(); } try { String fileName =
     * file.getOriginalFilename(); // id与filename保持一直，删除文件 String fileNameNew =
     * UUID.randomUUID().toString().replace("-", "") + getFileType(fileName);
     * String newFilePathName = newPath + fileNameNew; String url =
     * fileUploadProperties.getUrl() + "/" + createTime + "/" + fileNameNew; //
     * 创建输出文件对象 File outFile = new File(newFilePathName); // 拷贝文件到输出文件对象
     * FileUtils.copyInputStreamToFile(file.getInputStream(), outFile); //
     * 保存文件记录 FwdSjfjlbEntity fwdSjfjlbEntity = new FwdSjfjlbEntity();
     *
     * fwdSjfjlbEntity.setId(TsBqUtils.getUUID());
     * fwdSjfjlbEntity.setSjbh(sjbh); fwdSjfjlbEntity.setUrl(url);
     * fwdSjfjlbEntity.setCreateDate(new Date());
     * fwdSjfjlbEntity.setCreateId(currentUserId);
     * fwdSjfjlbEntity.setFileName(fileName);
     * fwdSjfjlbEntity.setFilePath(newFilePathName);
     *
     * this.save(fwdSjfjlbEntity);
     *
     * Map<String, String> resultMap = new HashMap<>(); resultMap.put("src",
     * url); return DataResult.success(resultMap); } catch (Exception e) { throw
     * new BusinessException("上传文件失败"); }
     *
     *
     *
     * return fwdSjfjlbService.saveFile(file, sjbh); }
     */

}
